/*
 * @Author: arvin(王德江)
 * @Date: 2022-08-18 21:44:01
 * @LastEditors: arvin(王德江)
 * @LastEditTime: 2022-08-25 22:15:01
 * @Description: 
 */
import {record} from 'rrweb'
import { saveAs } from 'file-saver';
// import RrwebPlayer from 'rrweb-player';
// import 'rrweb-player/dist/style.css';

let myEvents = [];
let errorIds= [] 

record({
  emit(event, isCheckout) {
    if(isCheckout)  {
      console.log('errorIds:', errorIds)
      errorIds.forEach(id => {
        const str = JSON.stringify({
          id,
          record: myEvents
        })
        let strData = new Blob([str], { type: '' });
        saveAs(strData, "replay.json");
        // fetch(new Request('', {
        //   method: 'post',
        //   headers: {'Content-Type': 'application/json;charset=utf-8'},
        //   body: JSON.stringify({
        //     id,
        //     record: myEvents
        //   })
        // })).then(null, (err) => {
        //   console.error(err)
        // })
      })
      errorIds = []
      myEvents = []
    }
    myEvents.push(event);
  },
  checkoutEveryNms: 10 * 1000,
},);

export default  function myRecord(id) {
  console.log(id)
  errorIds.push(id)
}


// const timer = setInterval(() => {
//   if(errorRecords.length < 2) return
  
//   clearInterval(timer)
// }, 1000)



// export const replay = function() {
//   replayer = new RrwebPlayer({
//     target: document.getElementById('replayer'),
//     props: {
//       events: errorRecords,
//       width: 500,
//       height: 500,
//       showWarning: false,
//       tags: {
//         error: 'red'
//       }
//     }
//   })
//   replayer.play();
// }

